package listbyorder.access001_100.test94;

import listbyorder.utils.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/6 9:11
 */
public class Solution1 {

    // 方法一：递归下的中序遍历
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> ans = new ArrayList<>();
        if (root == null) return ans;
        dfs(ans, root);
        return ans;
    }

    private void dfs(List<Integer> ans, TreeNode root) {
        if (root == null) return;
        dfs(ans, root.left);
        ans.add(root.val);
        dfs(ans, root.right);
    }
}
